<?php
/**
 * cingle functions and definitions.
 *
 * Sets up the theme and provides some helper functions, which are used
 * in the theme as custom template tags. Others are attached to action and
 * filter hooks in WordPress to change core functionality.
 *
 * @package cingle
 * @since cingle 1.0
 */

if( ! defined('CINGLE_DIR') ) {
	define( 'CINGLE_DIR', get_template_directory() . '/' );
}
if( ! defined('CINGLE_URI') ) {
	define( 'CINGLE_URI', get_template_directory_uri() . '/' );
}
/**
 * Include Option Tree framework for themeoptions
 */
include_once CINGLE_DIR . 'ot-loader.php';
include_once CINGLE_DIR . 'includes/posttype-members.php';
include_once CINGLE_DIR . 'includes/posttype-projects.php';
include_once CINGLE_DIR . 'includes/posttype-slides.php';
include_once CINGLE_DIR . 'includes/posttype-clients.php';
include_once CINGLE_DIR . 'includes/posttype-testimonials.php';
include_once CINGLE_DIR . 'admin/admin.php';

/**
 * Sets up the content width value based on the theme's design and stylesheet.
 */
if ( ! isset( $content_width ) )
	$content_width = 625;

/**
 * Sets up theme defaults and registers the various WordPress features that
 * Twenty Twelve supports.
 *
 * @uses load_theme_textdomain() For translation/localization support.
 * @uses add_editor_style() To add a Visual Editor stylesheet.
 * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
 * 	custom background, and post formats.
 * @uses register_nav_menu() To add support for navigation menus.
 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
 *
 * @since cingle 1.0
 */
function cingle_setup() {
	/*
	 * Makes Twenty Twelve available for translation.
	 *
	 * to change 'twentytwelve' to the name of your theme in all the template files.
	 */
	load_theme_textdomain( 'cingle', get_template_directory() . '/languages' );

	// This theme styles the visual editor with editor-style.css to match the theme style.
	add_editor_style();

	// Adds RSS feed links to <head> for posts and comments.
	add_theme_support( 'automatic-feed-links' );

	// This theme supports a variety of post formats.
	add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );

	// This theme uses wp_nav_menu() in one location.
	register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) );

	/*
	 * This theme supports custom background color and image, and here
	 * we also set up the default background color.
	 */
	add_theme_support( 'custom-background', array(
		'default-color' => 'e6e6e6',
	) );

	// This theme uses a custom image size for featured images, displayed on "standard" posts.
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop


}
add_action( 'after_setup_theme', 'cingle_setup' );

/**
 * Enqueue scripts and styles for front-end.
 *
 * @since cingle 1.0
 */
function cingle_scripts_styles() {
	wp_enqueue_script( 'bootstrap', CINGLE_URI . 'js/bootstrap.min.js' );
	wp_enqueue_script( 'custom', CINGLE_URI . 'js/custom.js', array( 'jquery', 'bootstrap') );
	wp_enqueue_style( 'cingle-style', get_stylesheet_uri() );

}
add_action( 'wp_enqueue_scripts', 'cingle_scripts_styles' );

/**
 * Enqueue scripts and styles for back-end
 *
 * @since  cingle 1.0
 */
function cingle_admin_scripts_styles() {
	wp_enqueue_style( 'ot-style', CINGLE_URI . 'css/ot-admin.css' );
}
add_action( 'admin_enqueue_scripts', 'cingle_admin_scripts_styles' );

/**
 * Creates a nicely formatted and more specific title element text
 * for output in head of document, based on current view.
 *
 * @since Twenty Twelve 1.0
 *
 * @param string $title Default title text for current view.
 * @param string $sep Optional separator.
 * @return string Filtered title.
 */
function cingle_wp_title( $title, $sep ) {
	global $paged, $page;

	if ( is_feed() )
		return $title;

	// Add the site name.
	$title .= get_bloginfo( 'name' );

	// Add the site description for the home/front page.
	$site_description = get_bloginfo( 'description', 'display' );
	if ( $site_description && ( is_home() || is_front_page() ) )
		$title = "$title $sep $site_description";

	// Add a page number if necessary.
	if ( $paged >= 2 || $page >= 2 )
		$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) );

	return $title;
}
add_filter( 'wp_title', 'cingle_wp_title', 10, 2 );

/**
 * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
 *
 * @since cingle 1.0
 */
function cingle_page_menu_args( $args ) {
	if ( ! isset( $args['show_home'] ) )
		$args['show_home'] = true;
	return $args;
}
add_filter( 'wp_page_menu_args', 'cingle_page_menu_args' );

/**
 * Registers our main widget area and the front page widget areas.
 *
 * @since cingle 1.0
 */
function cingle_widgets_init() {
	register_sidebar( array(
		'name' => __( 'Main Sidebar', 'cingle' ),
		'id' => 'sidebar-1',
		'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'cingle' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
}
add_action( 'widgets_init', 'cingle_widgets_init' );
